#ifndef EVENT_DISPATCHER_H
#define EVENT_DISPATCHER_H

#include "INonCopyable.h"
#include "IEventCallback.h"
#include "EventToCallback.h"

#include <ext/hash_map>
#include <ext/hash_set>

using __gnu_cxx::hash_set;
using __gnu_cxx::hash_map;

using Util::INonCopyable;
namespace Net{

    class EventDispatcher : public INonCopyable
    {
        public: 
            EventDispatcher();
            virtual ~EventDispatcher();

        public:
            int RegisterForRead(int fd, IEventCallback *callback);
            int RegisterForWrite(int fd, IEventCallback *callback);
            int RegisterForReadWrite(int fd, IEventCallback* callback);
            int RegisterEvent(int fd, IEventCallback* callback, 
                    int event);

            int WaitForEventAndExecute();

        protected:
            int ModFD(int fd, int event);
            int AddFD(int fd, int event);
            int DelFD(int fd);

        private:
            typedef hash_set<int, EventToCallback, EventToCallbackHash>
                EventHashSet;

            int             m_nEventFd;
            EventHashSet    m_setFdToCallback;
    };

    inline EventDispatcher::~EventDispatcher()
    {
    }

}
#endif
